package com.simple.piger.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.simple.piger.enums.ApplyUserEduEnums;
import com.simple.piger.utils.DateUtils;
import com.simple.piger.utils.PublicUtil;
import com.simple.piger.dto.resp.PlatformApplyUserListRespDto;
import com.simple.piger.entity.ApplyUser;
import com.simple.piger.enums.ApplyUserStatusEnums;
import com.simple.piger.enums.GenderEnums;
import com.simple.piger.mapper.ApplyUserMapper;
import com.simple.piger.service.ApplyUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 求职人员 服务实现类
 * </p>
 *
 * @author baolw
 * @since 2020-02-06
 */
@Service
public class ApplyUserServiceImpl extends ServiceImpl<ApplyUserMapper, ApplyUser> implements ApplyUserService {

    @Override
    public List<PlatformApplyUserListRespDto> platformApplyUserList(Integer page, Integer limit) {
        Integer start = PublicUtil.getPageStart(page, limit);
        List<PlatformApplyUserListRespDto> list = this.baseMapper.platformApplyUserList(start, limit);
        for (PlatformApplyUserListRespDto dto : list) {
            dto.setGenderValue(GenderEnums.transfer(dto.getGender()));
            dto.setStatusValue(ApplyUserStatusEnums.transfer(dto.getStatus()));
            dto.setCreateDate(DateUtils.dateFormat(dto.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        }
        return list;
    }

    @Override
    public int getPlatformApplyUserListCount() {
        return this.baseMapper.platformApplyUserListCount();
    }

    @Override
    public PlatformApplyUserListRespDto platformApplyDetail(String applyUserId) {
        ApplyUser applyUser = this.selectById(applyUserId);
        PlatformApplyUserListRespDto dto = new PlatformApplyUserListRespDto();
        BeanUtils.copyProperties(applyUser, dto);
        dto.setGenderValue(GenderEnums.transfer(applyUser.getGender()));
        dto.setStatusValue(ApplyUserStatusEnums.transfer(applyUser.getStatus()));
        dto.setCreateDate(DateUtils.dateFormat(applyUser.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        dto.setEduBackgroundValue(ApplyUserEduEnums.transfer(dto.getEduBackground()));
        return dto;
    }
}
